package com.rongzhe.house.ui.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.rongzhe.house.R;
import com.rongzhe.house.entity.voo.User;
import com.rongzhe.house.presenter.UserCenterPresenter;
import com.rongzhe.house.ui.activity.ListAppointmentActivity;
import com.rongzhe.house.ui.activity.OrderListActivity;
import com.rongzhe.house.ui.activity.UserInfoActivity;
import com.rongzhe.house.ui.view.CircleImageView;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by huang on 2017/12/10.
 */

public class UserCenterFragment extends BaseFragment<UserCenterPresenter> {
    @BindView(R.id.image_head)
    CircleImageView imageHead;
    @BindView(R.id.text_name)
    TextView textName;
    @BindView(R.id.container_header)
    RelativeLayout containerHeader;
    @BindView(R.id.text_appointment)
    TextView textHowGetMoney;
    Unbinder unbinder;

    @Override
    protected UserCenterPresenter createPresenter() {
        return new UserCenterPresenter(this);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_user_center, container, false);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.image_head)
    public void onHeadImageClick() {
        Intent intent = new Intent(getContext(), UserInfoActivity.class);
        launchActivity(true, intent);
    }

    @OnClick(R.id.text_appointment)
    public void onAppointmentClick() {
        Intent intent = new Intent(getContext(), ListAppointmentActivity.class);
        launchActivity(true, intent);
    }

    @OnClick(R.id.text_order)
    public void onOrderClick() {
        Intent intent = new Intent(getContext(), OrderListActivity.class);
        launchActivity(true, intent);
    }

    public void setImgHead(Bitmap finalPhotoBmp) {
        imageHead.setImageBitmap(finalPhotoBmp);
    }

    public void setImgHead(String url) {
        Picasso.with(getContext()).load(url).into(imageHead);
    }

    public void showUserInfo(User data) {
        if (data == null) {
            return;
        }
        textName.setText(data.getNickname());
        if (!TextUtils.isEmpty(data.getAvatar())) {
            setImgHead(data.getAvatar());
        }
    }
}
